using System;
using System.Collections.Generic;
using System.Text;

namespace BlackJackSimulator
    {

    public class Hand
        {
        private List<Card> m_hshCards= new List<Card>();
        private int m_ID=0;
        private int m_HandTotalValue=0;
        private bool m_HandBusted=false;
        private bool m_HandDidWin = false;
        private bool m_IsBlackjack = false;

        public Hand()
            {
           
            }
        public List<Card> CardsInHand
            {
            get
                {
                return m_hshCards;
                }
            }
     
	
        public bool DidHandWin
            {
            get { return m_HandDidWin; }
            set { m_HandDidWin = value; }
            }
        public void AddCardToHand(Card SelectedCard)
            {
            m_hshCards.Add(SelectedCard);
            CalcHandValue();

            }
        private double m_HandBetAmount;
        public double HandBetAmount
            {
            get { return m_HandBetAmount; }
            set { m_HandBetAmount = value; }
            }
        public bool Is_BlackJack
            {
            get { return m_IsBlackjack; }
            }
        public bool ResetHand()
            {
            this.m_HandDidWin = false;
            this.m_HandBusted = false;
            
            this.m_HandTotalValue = 0;
            this.m_ID = 1;
            this.CardsInHand.RemoveRange(0,m_hshCards.Count);
            return true;
            }
        public bool HandBusted
            {
            get { return m_HandBusted; }
            }
        private bool Calc_If_Hand_Blackjack()
            {
            if (m_hshCards.Count == 2)
                {
                if (m_hshCards[0].CardValue == CARD_VALUE.CD_VALUE_TYPES.A || m_hshCards[1].CardValue == CARD_VALUE.CD_VALUE_TYPES.A)
                    {
                    if (m_hshCards[0].NumberValueOfCard == 10 || m_hshCards[1].NumberValueOfCard == 10)
                        {
                        m_IsBlackjack = true;
                        m_HandTotalValue = 21; 
                        return true;

                        }
                    }

                }
            return false;

            }
        private bool Calc_If_Hand_Busted()
            {
            if (m_HandTotalValue > 21) { m_HandBusted = true; }
            else { m_HandBusted = false; }
            return m_HandBusted;
            }
        private void CalcHandValue()
            {
            m_HandTotalValue = 0;
            foreach (Card cCD in m_hshCards)
                {
                m_HandTotalValue += cCD.NumberValueOfCard;
                }

            Calc_If_Hand_Busted();
            Calc_If_Hand_Blackjack();
            }
        public int HandTotalValue
            {
            get
                {
                return m_HandTotalValue;
                }
            set
                {
                m_HandTotalValue = value;
                }
            }
        public int Hand_ID
            {
            get
                {
                return m_ID;
                }
            set
                {
                m_ID = value;
                }
            }
        }
    }
